<?php

class ActiveForm extends CActiveForm
{
	public $onlyScript = false;
	
	public function run()
	{
		if(is_array($this->focus))
			$this->focus="#".CHtml::activeId($this->focus[0],$this->focus[1]);
	
		echo CHtml::endForm();
		$cs=Yii::app()->clientScript;
		if(!$this->enableAjaxValidation && !$this->enableClientValidation || empty($this->attributes))
		{
			if($this->focus!==null)
			{
				$cs->registerCoreScript('jquery');
				$cs->registerScript('CActiveForm#focus',"
						if(!window.location.hash)
						$('".$this->focus."').focus();
						");
			}
			return;
		}
	
		$options=$this->clientOptions;
		if(isset($this->clientOptions['validationUrl']) && is_array($this->clientOptions['validationUrl']))
			$options['validationUrl']=CHtml::normalizeUrl($this->clientOptions['validationUrl']);
	
		$options['attributes']=array_values($this->attributes);
	
		if($this->summaryID!==null)
			$options['summaryID']=$this->summaryID;
	
		if($this->focus!==null)
			$options['focus']=$this->focus;
	
		$options=CJavaScript::encode($options);
		$cs->registerCoreScript('yiiactiveform');
		$id=$this->id;
		$cs->registerScript(__CLASS__.'#'.$id,"\$('#$id').yiiactiveform($options);");
		$cs->unRegisterCoreScript('jquery');
	}
}